import axios from "axios";
import store from '@/store';
// store.commit("loading/setloading");
//创建axios对象
const service = axios.create({
    baseURL:"/",
    timeout: 5000,   //超时
})
service.headers={
    "Content-Type": "application/json;charset=UTF-8",
  }
//配置请求拦截器
service.interceptors.request.use(
    config=>{
        //请求过程要做的事
        store.commit("loading/setloading",true);

        return config;
    },
    error=>{
        return Promise.reject(error);  //返回错误信息
    }
)


//配置响应的拦截器
service.interceptors.response.use(
    response =>{
        store.commit("loading/setloading",false);
        console.log(response);
        return response;
    },
    error =>{
        return Promise.reject(error);  //返回错误信息
    }
    
)


//导出
export default service